
//% color="#00c4dd" iconWidth=40 iconHeight=40
namespace AirQuality{
	
    //% block="init RX[RX] TX[TX]" blockType="command"
	//% RX.shadow="number" RX.defl="P0"
	//% TX.shadow="number" TX.defl="P1"
    export function init(parameter: any, block: any) {
	    let rx = parameter.RX.code;
		let tx = parameter.TX.code;
	    Generator.addInclude("includeAirQuality", "#include <AirQuality.h>");
		Generator.addObject(`AirQuality`,`AirQuality`,`aq(Serial1);`);
        Generator.addCode(`aq.begin(9600, SERIAL_8N1, ${rx}, ${tx});`);  	   
    }	
   
	//% block="read and parse data" blockType="boolean"
    export function is_get_data(parameter: any, block: any) {
		Generator.addCode(`aq.readAllData()`);	   
    }
		
	//% block="get eCO2 data" blockType="reporter"
    export function get_eco2(parameter: any, block: any) {
		Generator.addCode(`aq.getCO2()`);	   
    }
		
	//% block="get eCH20 data" blockType="reporter"
    export function get_ech20(parameter: any, block: any) {
		Generator.addCode(`aq.getCH2O()`);	   
    }	
		
	//% block="get TVOC data" blockType="reporter"
    export function get_tvoc(parameter: any, block: any) {
		Generator.addCode(`aq.getTVOC()`);	   
    }
		
	//% block="get PM2.5 data" blockType="reporter"
    export function get_pm2d5(parameter: any, block: any) {
		Generator.addCode(`aq.getPM25()`);	   
    }
		
	//% block="get PM10 data" blockType="reporter"
    export function get_pm10(parameter: any, block: any) {
		Generator.addCode(`aq.getPM10()`);	   
    }
		
	//% block="get Temperature data" blockType="reporter"
    export function get_temperature(parameter: any, block: any) {
		Generator.addCode(`aq.getTemperature()`);	   
    }
		
	//% block="get Humidity data" blockType="reporter"
    export function get_humidity(parameter: any, block: any) {
		Generator.addCode(`aq.getHumidity()`);	   
    }

	//% block="get eCO2 unit" blockType="reporter"
    export function get_eco2Unit(parameter: any, block: any) {
		Generator.addCode(`aq.getCO2Unit()`);	   
    }
		
	//% block="get eCH20 unit" blockType="reporter"
    export function get_ech20Unit(parameter: any, block: any) {
		Generator.addCode(`aq.getCH2OUnit()`);	   
    }	
		
	//% block="get TVOC unit" blockType="reporter"
    export function get_tvocUnit(parameter: any, block: any) {
		Generator.addCode(`aq.getTVOCUnit()`);	   
    }
		
	//% block="get PM2.5 unit" blockType="reporter"
    export function get_pm2d5Unit(parameter: any, block: any) {
		Generator.addCode(`aq.getPM25Unit()`);	   
    }
		
	//% block="get PM10 unit" blockType="reporter"
    export function get_pm10Unit(parameter: any, block: any) {
		Generator.addCode(`aq.getPM10Unit()`);	   
    }
		
	//% block="get Temperature unit" blockType="reporter"
    export function get_temperatureUnit(parameter: any, block: any) {
		Generator.addCode(`aq.getTemperatureUnit()`);	   
    }
		
	//% block="get Humidity unit" blockType="reporter"
    export function get_humidityUnit(parameter: any, block: any) {
		Generator.addCode(`aq.getHumidityUnit()`);	   
    }	
}
 